package com.itheima.cart.controller;


import com.itheima.api.client.ItemClient;
import com.itheima.cart.po.Cart;
import com.itheima.cart.service.ICartService;
import com.itheima.common.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private ICartService cartService;
    @Autowired
    private ItemClient itemClient;

    @PostMapping("/add")
    public Result add(Integer goodsId) {
        Cart cart = Cart.builder().goodsId(goodsId).build();
        cartService.save(cart);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        System.out.println("cart微服务这里收到的id:"+id);
        cartService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list() {
        return Result.success(itemClient.list());
    }
}
